package com.itheima.common;

/**
 * @Author itheima
 * @Date 2022/5/8 9:58
 * 自定义线程局部变量（ThreadLocal）：线程内部定义一个独立容器（存值也可以取值）
 */
public class BaseContext {
    private static final ThreadLocal<Long> THREAD_LOCAL_ID = new ThreadLocal<>();

    /**
     * 向ThreadLocal中存储值
     */
    public static void setThreadLocalId(Long id) {
        THREAD_LOCAL_ID.set(id);
    }

    /**
     * 从ThreadLocal中取值
     */
    public static Long getThreadLocalId() {
        return THREAD_LOCAL_ID.get();
    }
}
